package com.ruoyi.appreciate.teacomposition.controller;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.appreciate.teacomposition.domain.TeacherComposition;
import com.ruoyi.appreciate.teacomposition.service.ITeacherCompositionService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 教师作品Controller
 * 
 * @author duanxinli
 * @date 2025-09-15
 */
@RestController
@RequestMapping("/teacomposition/teacomposition")
public class TeacherCompositionController extends BaseController
{
    @Autowired
    private ITeacherCompositionService teacherCompositionService;

    /**
     * 查询教师作品列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(TeacherComposition teacherComposition)
    {
        startPage();
        List<TeacherComposition> list = teacherCompositionService.selectTeacherCompositionList(teacherComposition);
        return getDataTable(list);
    }

    /**
     * 导出教师作品列表
     */
    @PreAuthorize("@ss.hasPermi('teacomposition:teacomposition:export')")
    @Log(title = "教师作品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeacherComposition teacherComposition)
    {
        List<TeacherComposition> list = teacherCompositionService.selectTeacherCompositionList(teacherComposition);
        ExcelUtil<TeacherComposition> util = new ExcelUtil<TeacherComposition>(TeacherComposition.class);
        util.exportExcel(response, list, "教师作品数据");
    }

    /**
     * 获取教师作品详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(teacherCompositionService.selectTeacherCompositionById(id));
    }

    /**
     * 新增教师作品
     */
    @PreAuthorize("@ss.hasPermi('teacomposition:teacomposition:add')")
    @Log(title = "教师作品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeacherComposition teacherComposition)
    {
        return toAjax(teacherCompositionService.insertTeacherComposition(teacherComposition));
    }

    /**
     * 修改教师作品
     */
    @PreAuthorize("@ss.hasPermi('teacomposition:teacomposition:edit')")
    @Log(title = "教师作品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeacherComposition teacherComposition)
    {
        return toAjax(teacherCompositionService.updateTeacherComposition(teacherComposition));
    }

    /**
     * 删除教师作品
     */
    @PreAuthorize("@ss.hasPermi('teacomposition:teacomposition:remove')")
    @Log(title = "教师作品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(teacherCompositionService.deleteTeacherCompositionByIds(ids));
    }
}
